﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Web.UI.HtmlControls;
using System.Data;
public partial class AdminPortal_Controls_HeThong_LienKetWeb_List : System.Web.UI.UserControl
{
    string LangID = HNG.LIB.Localization.LocalizationUtils.GetCurrentLanguage();
    TblLienKetWebManager _TblLienKetWebManager = new TblLienKetWebManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            TblLienKetWebEntity _TblLienKetWebEntity = new TblLienKetWebEntity();
            _TblLienKetWebEntity.LangId = LangID;
            LoadDataToGrid(_TblLienKetWebEntity);
        }
    }

    private void LoadDataToGrid(TblLienKetWebEntity _TblLienKetWebEntity)
    {
        DataTable dt = _TblLienKetWebManager.be_SelectToGriView(_TblLienKetWebEntity);
        if (dt != null)
        {
            lblTotalRecord.Text = dt.Rows.Count.ToString();
            dgvListLienKetWeb.DataSource = dt;
            dgvListLienKetWeb.DataBind();
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/AdminPortal/Pages/LienKetWebAdd.aspx");
    }

    protected void btnDel_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in dgvListLienKetWeb.Rows)
        {
            HtmlInputCheckBox chkID = (HtmlInputCheckBox)row.FindControl("chkID");
            if (chkID.Checked)
            {
                try
                {
                    _TblLienKetWebManager.DeleteById(Convert.ToInt32(chkID.Value));
                }
                catch { }
            }
        }
        LoadDataToGrid(new TblLienKetWebEntity());
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        TblLienKetWebEntity _TblLienKetWebEntity = new TblLienKetWebEntity();
        _TblLienKetWebEntity.SortDirection = "ASC";
        _TblLienKetWebEntity.Condition = txtKeySearch.Text;
        _TblLienKetWebEntity.LangId = LangID;

        LoadDataToGrid(_TblLienKetWebEntity);

    }
    protected void dgvListLienKetWeb_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataRowView r = (DataRowView)e.Row.DataItem;

        HyperLink lnkName = (HyperLink)e.Row.FindControl("lnkName");

        Image imgUpdate = (Image)e.Row.FindControl("imgUpdate");

        if (r != null && lnkName != null && imgUpdate != null)
        {
            lnkName.Text = r[TblLienKetWebFields.TenLienKet.Name].ToString();
            lnkName.NavigateUrl = "~/AdminPortal/Pages/LienKetWebEdit.aspx?id=" + r[TblLienKetWebFields.Id.Name].ToString();

            if (r[TblLienKetWebFields.TrangThai.Name].ToString().Equals("True"))
                imgUpdate.ImageUrl = "~/AdminPortal/Images/Icon/tree_dnd_yes.png";
            else
                imgUpdate.ImageUrl = "~/AdminPortal/Images/Icon/tree_dnd_no.png";
            imgUpdate.Attributes.Add("onclick", "javascript:changeStatusLienKetWeb('" + imgUpdate.ClientID + "','" + r[TblLienKetWebFields.Id.Name].ToString() + "')");

        }
    }
}